//
//  IdentityThirdViewController.m
//  CommunityApp
//
//  Created by 秦乾龙 on 16/12/29.
//  Copyright © 2016年 秦乾龙. All rights reserved.
//

#import "IdentityThirdViewController.h"
#import "ZYButton.h"
#import "NavView.h"
#import "Province.h"
#import "City.h"
#import "IdentityFourViewController.h"
#import "WDData.h"
#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height
#define kScale   ([UIScreen mainScreen].bounds.size.width)/750
@interface IdentityThirdViewController ()<UITextFieldDelegate,UITextViewDelegate,UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,retain) UITableView *mainTableView;
@property (nonatomic,retain) UITableView *bankTableView;
@property (nonatomic,retain) UITableView *provinceTableView;
@property (nonatomic,retain) UITableView *cityTableView;
@property (nonatomic,copy) UITextField *nameField;
@property (nonatomic,copy) UITextField *cardNumField;
@property (nonatomic,copy) UITextField *bankDetailNameField;
@property (nonatomic,copy) UITextField *codeField;
@property (nonatomic,copy) NSMutableArray *classNameArr;
@property (nonatomic,copy) NSMutableArray *bankArr;
@property (nonatomic,copy) NSMutableArray *provinceArr;
@property (nonatomic,copy) NSMutableArray *cityArr;
@property (nonatomic,copy) NSMutableArray *stepFinishedImgArr;
@property (nonatomic,copy) NSMutableArray *stepUnFinishedImgArr;
@property (nonatomic,copy) ZYButton *provinceBtn;
@property (nonatomic,copy) ZYButton *cityBtn;
@property (nonatomic,copy) ZYButton *bankBtn;
@property (nonatomic,copy) UILabel *pTitleLable;
@property (nonatomic,copy) UILabel *cTitleLable;
@property (nonatomic,copy) UILabel *bTitleLable;
@property (nonatomic,assign) BOOL provinceBtnSelect;
@property (nonatomic,assign) BOOL cityBtnSelect;
@property (nonatomic,assign) BOOL bankBtnSelect;
@property (nonatomic,copy) NSString *pId;
@property (nonatomic,copy) NSString *pName;
@property (nonatomic,copy) NSString *cName;

@end

@implementation IdentityThirdViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   
    _stepFinishedImgArr = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4", nil];
    _stepUnFinishedImgArr = [NSMutableArray arrayWithObjects:@"1灰",@"2灰",@"3灰",@"4灰", nil];
    _classNameArr = [NSMutableArray arrayWithObjects:@"开户银行",@"开户行所在地",@"开户行名称",@"银行卡号", nil];
    _bankArr = [NSMutableArray arrayWithObjects:@"中国工商银行",@"中国建设银行",@"中国银行",@"中国农业银行",@"交通银行",@"中信银行",@"中国民生银行",@"兴业银行",@"上海浦东发展银行",@"中国邮政储蓄银行",@"平安银行",@"华夏银行", @"中国光大银行",@"北京银行",nil];
    _provinceArr = [NSMutableArray array];
    _cityArr = [NSMutableArray array];
    _bankBtnSelect = NO;
    _provinceBtnSelect = NO;
    _cityBtnSelect = NO;
    _pId = @"18";
    [self setUI];
}
- (void) setUI
{
    self.navigationItem.titleView = [ViewFactory makeNavigationTitle:@"身份认证"];
    
    UIBarButtonItem *backBtn = [ViewFactory makeNavigationBackWhite:self action:@selector(backClick)];
    self.navigationItem.leftBarButtonItem = backBtn;
    
    UIButton *buttonNotice = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonNotice.frame = CGRectMake(0, 0, 40, 40);
    [buttonNotice setTitle:@"提交" forState:UIControlStateNormal];
    buttonNotice.titleLabel.font = [UIFont systemFontOfSize:13];
    UIBarButtonItem *btnNoticeItem = [[UIBarButtonItem alloc]initWithCustomView:buttonNotice];
    [buttonNotice addTarget:self action:@selector(nextClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = btnNoticeItem;
    
    _mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,kScreenW , kScreenH-64) style:UITableViewStyleGrouped];
    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
    _mainTableView.tag = 20;
    [self.view addSubview:_mainTableView];
//    _classNameArr = [NSMutableArray arrayWithObjects:@"上传身份证正面",@"上传身份证反面",@"上传手持身份证头部照", nil];
    _bankTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];
    _bankTableView.delegate = self;
    _bankTableView.dataSource = self;
    _bankTableView.tag = 23;
    _bankTableView.separatorStyle = NO;
    [self.view addSubview:_bankTableView];
    _provinceTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];
    _provinceTableView.delegate = self;
    _provinceTableView.dataSource = self;
    _provinceTableView.tag = 21;
    _provinceTableView.separatorStyle = NO;
    [self.view addSubview:_provinceTableView];
    _cityTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];
    _cityTableView.delegate = self;
    _cityTableView.dataSource = self;
    _cityTableView.tag = 22;
    _cityTableView.separatorStyle = NO;
    [self.view addSubview:_cityTableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (tableView.tag == 20) {
        return 3;
    }
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView.tag == 20) {
        if (section==2)
        {
            return 4;
        }
        return 1;
    }
    else if (tableView.tag==21)
    {
        return _provinceArr.count;
    }
    else if (tableView.tag==22)
    {
        return _cityArr.count;
    }
    else if (tableView.tag==23)
    {
        return _bankArr.count;
    }
    return 0;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell)
    {
        cell =[[NSBundle mainBundle ]loadNibNamed:@"ZYTableViewCell" owner:nil options:nil][0];
    }
    //设置cell点击背景色不变
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    if (tableView.tag==20) {
        if (indexPath.section==0)
        {
            UIView *stateView = [[UIView alloc]init];
            stateView.frame = CGRectMake(0, 0, kScreenW, 200*kScale);
            stateView.backgroundColor = [UIColor whiteColor];
            [cell addSubview:stateView];
            NSMutableArray *lableTextArr = [NSMutableArray arrayWithObjects:@"填充信息",@"上传照片",@"选择收款方式",@"提交审核", nil];
            for (int i = 0; i<4; i++)
            {
                CGFloat errorW = 5*kScale;
                CGFloat stateBtnH = 82*kScale;
                CGFloat lineViewW = (kScreenW - 60*kScale -4*stateBtnH)/3+errorW;
                CGFloat lineViewH = 6*kScale;
                ZYButton *stateBtn = [ZYButton buttonWithType:UIButtonTypeCustom];
                
                
                stateBtn.frame = CGRectMake(30*kScale+(stateBtnH+lineViewW-errorW)*i, 30*kScale, stateBtnH, stateBtnH);
                
                if (i==2)
                {
                    [stateBtn setImage:[UIImage imageNamed:_stepFinishedImgArr[i]] forState:UIControlStateNormal];
                }
                else
                {
                    [stateBtn setImage:[UIImage imageNamed:_stepUnFinishedImgArr[i]] forState:UIControlStateNormal];
                    
                }
                if (i!=0)
                {
                    UIView *lineView = [[UIView alloc]init];
                    lineView.frame = CGRectMake(30*kScale+(stateBtnH+lineViewW-errorW)*i-lineViewW+errorW/2, stateBtn.center.y, lineViewW, lineViewH);
                    stateBtn.lineView = lineView;
                    stateBtn.lineView.backgroundColor = ZallColorFromRGB(0x979797);
                    [stateView addSubview:lineView];
                    
                }
                [stateView addSubview:stateBtn];
                
                UILabel *stateLable = [[UILabel alloc]init];
                stateLable.text = lableTextArr[i];
                stateLable.frame = CGRectMake(0, 0, kScreenW, 40*kScale);
                stateLable.center = CGPointMake(stateBtn.center.x, stateBtn.center.y+stateBtnH/2+31*kScale);
                stateLable.textAlignment = NSTextAlignmentCenter;
                stateLable.font = [UIFont systemFontOfSize:13];
                [stateView addSubview:stateLable];
            }
        }
        else if (indexPath.section==1)
        {
            UIButton *boolSelectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [boolSelectBtn setImage:[UIImage imageNamed:@"选择默认地址图标"] forState:UIControlStateNormal];
            [boolSelectBtn setImage:[UIImage imageNamed:@"选择默认地址图标"] forState:UIControlStateSelected];
            boolSelectBtn.frame = CGRectMake(300*kScale, 29*kScale, 42*kScale, 42*kScale);
            [cell addSubview:boolSelectBtn];
            UILabel *payClassLable = [[UILabel alloc]init];
            payClassLable.backgroundColor = [UIColor clearColor];
            payClassLable.text = @"银行卡";
            payClassLable.font = [UIFont systemFontOfSize:15];
            payClassLable.frame = CGRectMake(300*kScale+42*kScale+20*kScale, 29*kScale, kScreenW, 42*kScale);
            [cell addSubview:payClassLable];
        }
        else if (indexPath.section==2)
        {
            UILabel *classNameLable = [[UILabel alloc]init];
            classNameLable.text = [NSString stringWithFormat:@"%@:",_classNameArr[indexPath.row]];
            classNameLable.font = [UIFont systemFontOfSize:15];
            NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
            //        classNameLable.textColor = [UIColor colorWithRed:158/255.0 green:158/255.0 blue:158/255.0 alpha:1.0f];
            CGSize textSize = [@"开户行所在地:" boundingRectWithSize:CGSizeMake(MAXFLOAT, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;;
            classNameLable.frame = CGRectMake(30*kScale, 0, textSize.width, 100*kScale);
            [cell addSubview:classNameLable];
            
            if (indexPath.row==0)
            {
                CGFloat btnW = 451*kScale;
                CGFloat btnH = 52*kScale;
                CGFloat titleW = 399*kScale;
                _bankBtn = [ZYButton buttonWithType:UIButtonTypeRoundedRect];
                
                _bankBtn.frame = CGRectMake(30*kScale+textSize.width+38*kScale, 24*kScale, btnW, btnH);
                [_bankBtn setBackgroundImage:[UIImage imageNamed:@"开户银行@1x"] forState:UIControlStateNormal];
                [_bankBtn addTarget:self action:@selector(chooseBank:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:_bankBtn];
                _bTitleLable = [[UILabel alloc]init];
                _bTitleLable.frame = CGRectMake(0, 0, titleW, btnH);
                _bTitleLable.text = @"中国工商银行";
                _bTitleLable.font = [UIFont systemFontOfSize:13];
                _bTitleLable.textColor = ZallColorFromRGB(0x9e9e9e);
                _bTitleLable.textAlignment = NSTextAlignmentCenter;
                _bTitleLable.adjustsFontSizeToFitWidth = YES;
                [_bankBtn addSubview:_bTitleLable];
            }
            else if(indexPath.row==1)
            {
                CGFloat btnW = 226*kScale;
                CGFloat btnH = 52*kScale;
                CGFloat titleW = 174*kScale;
                _provinceBtn = [ZYButton buttonWithType:UIButtonTypeRoundedRect];
                
                _provinceBtn.frame = CGRectMake(30*kScale+textSize.width+38*kScale, 24*kScale, btnW, btnH);
                //            [_provinceBtn setImage:[UIImage imageNamed:@"选择省份"] forState:UIControlStateNormal];
                [_provinceBtn setBackgroundImage:[UIImage imageNamed:@"选择省份"] forState:UIControlStateNormal];
                
                [_provinceBtn addTarget:self action:@selector(chooseProvince:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:_provinceBtn];
                _pTitleLable = [[UILabel alloc]init];
                _pTitleLable.frame = CGRectMake(0, 0, titleW, btnH);
                _pTitleLable.text = @"湖北";
                _pTitleLable.font = [UIFont systemFontOfSize:13];
                _pTitleLable.textColor = ZallColorFromRGB(0x9e9e9e);
                _pTitleLable.textAlignment = NSTextAlignmentCenter;
                _pTitleLable.adjustsFontSizeToFitWidth = YES;
                [_provinceBtn addSubview:_pTitleLable];
                
                //            _provinceTableView = [[UITableView alloc]initWithFrame:CGRectMake(_provinceBtn.frame.origin.x, _provinceBtn.frame.origin.y,titleW , 216*kScale) style:UITableViewStyleGrouped];
                //            _provinceTableView.delegate = self;
                //            _provinceTableView.dataSource = self;
                //            [cell addSubview:_provinceTableView];
                _cityBtn = [ZYButton buttonWithType:UIButtonTypeRoundedRect];
                
                _cityBtn.frame = CGRectMake(30*kScale+textSize.width+38*kScale*2+btnW, 24*kScale, btnW, btnH);
                //            [_provinceBtn setImage:[UIImage imageNamed:@"选择省份"] forState:UIControlStateNormal];
                [_cityBtn setBackgroundImage:[UIImage imageNamed:@"选择省份"] forState:UIControlStateNormal];
                
                [_cityBtn addTarget:self action:@selector(chooseCity:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:_cityBtn];
                _cTitleLable = [[UILabel alloc]init];
                _cTitleLable.frame = CGRectMake(0, 0, titleW, btnH);
                _cTitleLable.text = @"武汉";
                _cTitleLable.font = [UIFont systemFontOfSize:13];
                _cTitleLable.textColor = ZallColorFromRGB(0x9e9e9e);
                _cTitleLable.textAlignment = NSTextAlignmentCenter;
                _cTitleLable.adjustsFontSizeToFitWidth = YES;
                [_cityBtn addSubview:_cTitleLable];
                
            }
            else if(indexPath.row==2)
            {
                
                _bankDetailNameField = [[UITextField alloc]init];
                _bankDetailNameField.delegate = self;
                _bankDetailNameField.font = [UIFont systemFontOfSize:15];
                _bankDetailNameField.frame = CGRectMake(30*kScale+textSize.width+38*kScale, 0, kScreenW-30*kScale-textSize.width-38*kScale, 100*kScale);
                _bankDetailNameField.placeholder = @"请输入您的开户行所在地";
                
                [cell addSubview:_bankDetailNameField];
                
            }
            else if(indexPath.row==3)
            {
                _cardNumField = [[UITextField alloc]init];
                _cardNumField.delegate = self;
                _cardNumField.font = [UIFont systemFontOfSize:15];
                _cardNumField.frame = CGRectMake(30*kScale+textSize.width+38*kScale, 0, kScreenW-30*kScale-textSize.width-38*kScale, 100*kScale);
                _cardNumField.placeholder = @"请输入您的银行卡号";
                _cardNumField.keyboardType = UIKeyboardTypeNumberPad;
                [cell addSubview:_cardNumField];
                
            }
        }

    }
    else if (tableView.tag==21)
    {
        UILabel *provinceLable = [[UILabel alloc]init];
        provinceLable.frame = CGRectMake(0, 0, 174*kScale, 50*kScale);
        Province *p = _provinceArr[indexPath.row];
        provinceLable.text = p.name;
        provinceLable.font = [UIFont systemFontOfSize:15];
        provinceLable.textColor = ZallColorFromRGB(0x9e9e9e);
        provinceLable.textAlignment = NSTextAlignmentCenter;
        //字体大小随字数变化
        provinceLable.adjustsFontSizeToFitWidth = YES;
        
        [cell addSubview:provinceLable];
    }
    else if (tableView.tag==22)
    {
        UILabel *cityLable = [[UILabel alloc]init];
        cityLable.frame = CGRectMake(0, 0, 174*kScale, 50*kScale);
        City *c = _cityArr[indexPath.row];
        cityLable.text = c.cityName;
        cityLable.font = [UIFont systemFontOfSize:15];
        cityLable.textColor = ZallColorFromRGB(0x9e9e9e);
        cityLable.textAlignment = NSTextAlignmentCenter;
        //字体大小随字数变化
        cityLable.adjustsFontSizeToFitWidth = YES;
        
        [cell addSubview:cityLable];
    }
    else if (tableView.tag==23)
    {
        UILabel *bankLable = [[UILabel alloc]init];
        bankLable.frame = CGRectMake(0, 0, 399*kScale, 52*kScale);
        bankLable.text = _bankArr[indexPath.row];
        bankLable.font = [UIFont systemFontOfSize:15];
        bankLable.textColor = ZallColorFromRGB(0x9e9e9e);
        bankLable.textAlignment = NSTextAlignmentCenter;
        //字体大小随字数变化
        bankLable.adjustsFontSizeToFitWidth = YES;
        
        [cell addSubview:bankLable];
    }
    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 20) {
        if (indexPath.section==0) {
            return 200*kScale;
        }
        return  100*kScale;
    }
    return 50*kScale;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return  0.01;
    }
    return 20*kScale;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag==20)
    {
        
    }
    else if (tableView.tag==21)
    {
        _provinceTableView.frame = CGRectMake(0, 0, 0, 0);
        _provinceBtnSelect = !_provinceBtnSelect;
//        UITableViewCell *cell = (UITableViewCell*)[_provinceTableView cellForRowAtIndexPath:indexPath];
        
        Province *p = _provinceArr[indexPath.row];
        _pTitleLable.text = p.name;
        _pId = p.pId;
        NSLog(@"777777%@",_pId);
        _cityBtnSelect = YES;
        [self chooseCity:nil];
    }
    else if (tableView.tag==22)
    {
        _cityTableView.frame = CGRectMake(0, 0, 0, 0);
        _cityBtnSelect = !_cityBtnSelect;
        
        City *c = _cityArr[indexPath.row];
        _cTitleLable.text = c.cityName;
    }
    else if (tableView.tag==23)
    {
        _bankTableView.frame = CGRectMake(0, 0, 0, 0);
        _bankBtnSelect = !_bankBtnSelect;
        _bTitleLable.text = _bankArr[indexPath.row];
    }
}
- (void)backClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)nextClick
{
    WDData *data = [WDData sharedWDData];
    NSString *urlStr = [[NSString stringWithFormat:@"%@/userCenter/checkSellerstate?user_name=%@&idcar=%@&send_sheng=%@&send_city=%@&moblie_no=%@&sms=%@&front_idcar=%@&negative_idcar=%@&head_idcar=%@&pay_way=%@&pay_number=%@&open_bank=%@&open_sheng=%@&open_city=%@&open_name=%@",APIYIGOU,data.reallyName,data.idcar,data.province,data.city,data.mobile,data.sms,data.imgArr[0],data.imgArr[1],data.imgArr[2],@"银行卡",_cardNumField.text,_bTitleLable.text,_pTitleLable.text,_cTitleLable.text,_bankDetailNameField.text]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    DYLog(@"%@",urlStr);
    DYBaseRequest *request = [DYBaseRequest new];
    request.requestUrl = urlStr;
    [request dyBgStartWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        NSDictionary *allDic = [NSDictionary changeType:request.responseJSONObject];
        NSLog(@"allDic===%@",allDic);
        IdentityFourViewController *four = [[IdentityFourViewController alloc]init];
        [self.navigationController pushViewController:four animated:YES];
    } error:^(YTKBaseRequest *request) {
        [ViewFactory showInfoMsg:@"提交失败"];
    } failure:^(YTKBaseRequest *request) {
        [ViewFactory showErrorStrMsg:NETWORK_ERR];
    }];
    
    
}

//选择银行
- (void)chooseBank:(ZYButton*)sender
{
    if (_bankBtnSelect==NO) {
        UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
        CGRect rect=[_bankBtn convertRect: _bankBtn.bounds toView:window];
        _bankTableView.frame = CGRectMake(rect.origin.x, rect.origin.y-64+52*kScale, 399*kScale, 216*kScale);
    }
    else
    {
        _bankTableView.frame = CGRectMake(0, 0, 0, 0);
    }
    _bankBtnSelect = !_bankBtnSelect;
    
}
//选择省份
- (void)chooseProvince:(ZYButton*)sender
{
    if (_provinceBtnSelect==NO) {
        UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
        CGRect rect=[_provinceBtn convertRect: _provinceBtn.bounds toView:window];
        _provinceTableView.frame = CGRectMake(rect.origin.x, rect.origin.y-64+52*kScale, 174*kScale, 216*kScale);
        
        NSString *urlStr = [NSString stringWithFormat:@"%@/userCenter/getAllSheng",APIYIGOU];
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        manager.requestSerializer = [AFJSONRequestSerializer serializer];
        [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [manager.requestSerializer setValue:[UserData usertoken] forHTTPHeaderField:@"Auth"];
        manager.responseSerializer = [AFHTTPResponseSerializer serializer];
        [manager POST:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
            NSArray *arr = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            DYLog(@"123456%@",arr);
            [_provinceArr removeAllObjects];
            for (int i=0; i<arr.count; i++)
            {
                Province *p = [[Province alloc]initWithName:arr[i][@"regionName"] Id:arr[i][@"id"] cities:nil];
                [_provinceArr addObject:p];
            }
            [_provinceTableView reloadData];
            
        } failure:^(NSURLSessionDataTask *task, NSError *error) {
            [ViewFactory showErrorStrMsg:NETWORK_ERR];
        }];
    }
    else
    {
        _provinceTableView.frame = CGRectMake(0, 0, 0, 0);
    }
    _provinceBtnSelect = !_provinceBtnSelect;
    
}
//选择市区
- (void)chooseCity:(ZYButton*)sender
{
    NSString *urlStr = [NSString stringWithFormat:@"%@/userCenter/getAllCL?id=%@",APIYIGOU,_pId];
    DYLog(@"....%@",_pId);
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [manager.requestSerializer setValue:[UserData usertoken] forHTTPHeaderField:@"Auth"];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSArray *arr = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        DYLog(@"123456%@",arr);
        [_cityArr removeAllObjects];
        for (int i=0; i<arr.count; i++)
        {
            City *c = [[City alloc]init];
            c.cityName = arr[i][@"regionName"];
            
            c.cityId = arr[i][@"id"];
            [_cityArr addObject:c];
            if (i==0) {
                _cTitleLable.text = c.cityName;
            }
        }
        
        [_cityTableView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [ViewFactory showErrorStrMsg:NETWORK_ERR];
    }];
    if (_cityBtnSelect==NO) {
        UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
        CGRect rect=[_cityBtn convertRect: _cityBtn.bounds toView:window];
        _cityTableView.frame = CGRectMake(rect.origin.x, rect.origin.y-64+52*kScale, 174*kScale, 216*kScale);
        
        
        
    }
    else
    {
        _cityTableView.frame = CGRectMake(0, 0, 0, 0);
    }
    _cityBtnSelect = !_cityBtnSelect;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
